<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://cdn.bootcss.com/animate.css/3.5.2/animate.min.css">
</head>
<body>
    <div id="app">
        <big-brother></big-brother>   
        <hr>
        <littel-brother ref="littel"></littel-brother>
    </div>


    <template id="big-brother">
        <div>
            <p>我是哥哥</p>
            <button @click="hitLittel">打弟弟</button>
        </div>
    </template>


    <template id="littel-brother">
        <div>
            <p>我是弟弟</p>
            <p v-if="crying">呜呜呜呜~~~</p>
        </div>
    </template>

</body>
<script src="./base/vue.js"></script>

<script>
    //在兄弟组件之间的通信，可以采用关系链和ref链去使用，解决兄弟之间通信问题。
    Vue.component("big-brother",{
        template:"#big-brother",
        methods:{
            hitLittel(){
                //更改弟弟crying状态
                // this.$parent.$children[1].crying=true //纯粹的关系链
                this.$parent.$refs.littel.crying = true; //关系链+ref链
            }
        }
    })
    Vue.component("littel-brother",{
        template:"#littel-brother",
        data(){
            return {
                crying:false
            }
        }
    })
    
    new Vue({
        el:"#app"
    })


</script>
</html>